﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace K3R.EventLogging {
	public class Log {
		public string LogName { get; set; }
		public string Source { get; set; }

		public Log(string logName, string source) {
			LogName = logName;
			Source = source;

			try {
				if (!EventLog.SourceExists(Source))
					EventLog.CreateEventSource(source, logName);
			}
			catch { }
		}

		public void WriteToLog(string message, EventLogEntryType type) {
			EventLog evt = new EventLog(LogName);
			string entryString = message + ": "
			  + DateTime.Now.ToShortDateString() + " "
			  + DateTime.Now.ToLongTimeString();
			evt.Source = Source;

			try {
				evt.WriteEntry(entryString, type);
			}
			catch { }
		}

		public void Info(string message) {
			WriteToLog(message, EventLogEntryType.Information);
		}

		public void Warn(string message) {
			WriteToLog(message, EventLogEntryType.Warning);
		}

		public void Error(string message) {
			WriteToLog(message, EventLogEntryType.Error);
		}
	}
}